package com.game.ThauanLopes.Enemies;

import java.util.HashSet;
import java.util.Random;

import com.game.ThauanLopes.Game;
import com.game.ThauanLopes.GameObject;
import com.game.ThauanLopes.R;
import com.game.ThauanLopes.Sprite;
import com.game.ThauanLopes.R.id;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

public class Medium extends GameObject {

	// Extrinsic values
		public int xVelocity = 8;
		
		private int bitmapId = R.drawable.enemy;
		
		private int width;
		private int height;
		
		private int initialDistancePos = 10;
	
		// Intrinsic values
		private Bitmap enemieBitmap;
		private Sprite sprite;

		private int x;
		private int y;
		
		public Paint paint;
		public int gameCanvasWidth;
		public int gameCanvasHeight;

	
	public Medium(int canvasWidth, int canvasHeight, HashSet<GameObject> hs)
	{
		this.paint = new Paint();
		
		this.gameCanvasWidth = canvasWidth;
		this.gameCanvasHeight = canvasHeight;
		
		this.enemieBitmap = BitmapFactory.decodeResource(Game.resources, bitmapId);
		this.sprite = new Sprite(this.enemieBitmap, 1, 1);
		
		// Randomize the instantiate side
		Random random = new Random();
		int temp = random.nextInt(2);
		if(temp == 1)
		{
			this.x = 0 - this.initialDistancePos; 
			
		}
		else 
		{ 
			this.x = this.gameCanvasWidth + this.initialDistancePos;
			xVelocity = -xVelocity;
		} 
		
		this.y = Game.floor;
		
		hs.add(this);
		
	}

	public void Update()
	{
		x += xVelocity;
	
		this.sprite.Update(Game.deltaTime);
	}
	@Override
	public void Draw(Canvas canvas)
	{
		Rect destRect = new Rect(this.x, Game.floor - this.height, this.x + this.width, Game.floor);
		this.sprite.Draw(canvas, destRect);
	}
	
	public void SetPotsition(float x, float y)
	{
		this.x = (int) x;
		this.y = (int) y;
	}

	@Override
	public boolean collision(Rect rect) {
		
		Rect myRect = new Rect(x, y, x + this.width, y + this.height);
		boolean state = false;
		
		if(rect.intersect(myRect))
		{
			state = true;
		}
		
		return state;
	}


}
